package Leetcode.array;

import java.util.Arrays;

public class Twosum {
    public int[] twoSum(int[] nums, int target) {
        int[] arr=Arrays.copyOf(nums,nums.length);
        Arrays.sort(arr);
        int i=0;
        int j=arr.length-1;
        for(;i<j;){
            int sum;
            sum=arr[i]+arr[j];
            if(sum==target)
                break;
            if(sum>target)
                j--;
            else
                i++;
        }
        int[] a={0,0};
        System.out.println(arr[i]);
        System.out.println(arr[j]);
        System.out.println("---------");
        for(int m=0;m<nums.length;m++){
            System.out.println(nums[m]);
        }
        int t=0;
        for(int m=0;m<nums.length;m++){
            if(nums[m]==arr[i]||nums[m]==arr[j])
                a[t++]=m;

        }
        return a;
    }

    public static void main(String[] args) {
           int[] arr={3,2,4};
           int tar=6;
           Twosum s=new Twosum();
           int[] b=s.twoSum(arr,tar);

           for(int i=0;i<b.length;i++)
               System.out.println(b[i]);
    }
}
